package gui.FileTransfer;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;

import javax.swing.*;

public class FileTransferPanel extends JPanel
{
	public static enum TRANSFER_MODES { TM_UPLOAD, TM_DOWNLOAD };
	
	protected JProgressBar pb;
	protected JLabel lblStatus;
	protected String filename;
	protected TRANSFER_MODES mode;
	
	public FileTransferPanel(String filename, int fileSize, TRANSFER_MODES mode)
	{
		super();
		pb = new JProgressBar(0, fileSize);
		lblStatus = new JLabel("no file (0%)");
		this.filename = new String(filename);
		this.mode = mode;
		
		GridBagConstraints c = new GridBagConstraints();		
		GridBagLayout layout = new GridBagLayout();		
		setLayout(layout);
		
		c.gridx = 0;
		c.gridy = 0;		
		c.fill = GridBagConstraints.NONE;
		this.add(lblStatus, c);
		
		c.gridy = 1;
		this.add(pb, c);
	}
	
	public void setProgress(int bytes)
	{		
		String percentage = " ("+ (int) (((double) bytes) / pb.getMaximum() * 100) + "%)";
		
		switch(mode)
		{
			case TM_DOWNLOAD:
				lblStatus.setText("Downloading "+filename+" "+percentage);
				break;
				
			case TM_UPLOAD:
				lblStatus.setText("Uploading "+filename+" "+percentage);
				break;						
		} // SWITCH
		
		pb.setValue(bytes);
	}
}
